local assets = {
	Asset("ANIM", "anim/lightning.zip"),
	Asset("ANIM", "anim/musha_lightning_blue.zip")
}

local function common_fn(name)
	local inst = CreateEntity()

	inst.entity:AddTransform()
	inst.entity:AddNetwork()

	inst:AddTag("FX")

	--Delay one frame so that we are positioned properly before starting the effect
	--or in case we are about to be removed
	inst:DoTaskInTime(
		0,
		function(proxy)
			local pos = Vector3(proxy.Transform:GetWorldPosition())
			local inst = CreateEntity()

			inst:AddTag("FX")
			--[[Non-networked entity]]
			inst.entity:SetCanSleep(false)
			inst.persists = false

			inst.entity:AddTransform()
			inst.entity:AddAnimState()
			inst.entity:AddLight()

			inst.Transform:SetPosition(pos:Get())
			inst.Transform:SetScale(2, 2, 2)

			inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
			inst.AnimState:SetLightOverride(1)
			inst.AnimState:SetBuild(name)
			inst.AnimState:PlayAnimation("anim")

			inst:ListenForEvent("animover", inst.Remove)
		end
	)

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst.entity:SetCanSleep(false)
	inst.persists = false
	inst:DoTaskInTime(1, inst.Remove)

	return inst
end

local function musha_lightning()
	return common_fn("lightning")
end

local function musha_lightning_blue()
	return common_fn("musha_lightning_blue")
end

return Prefab("musha_lightning", musha_lightning, assets), Prefab("musha_lightning_blue", musha_lightning_blue, assets)
